﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using transportsystem.DTO;
using UTIL;

namespace transportsystem.DAO
{
    public class NhanVienDAO
    {


        public static DataTable getNhanVienList(params SqlParameter[] Params)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_TraCuuNhanVien";
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, Params);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }
        public static int thaoTacNhanVien(params SqlParameter[] Params)
        {

            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_nhanvien";
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, Params);
            if (ds != null)
                return 1;
            return 0;

        }
        public static bool deleteNhanVien(NhanVien nv)
        {
            SqlCommand cmd = SqlDataAccessHelper.CreateCommand("sp_XoaNhanVien");
            cmd.Parameters.Add("@manv", SqlDbType.Int).Value = nv.Manv;
            return SqlDataAccessHelper.ExecCmd(cmd);
        }
        public static DataTable getNhanVienID(params SqlParameter[] Params)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_TraCuuNhanVienID";
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, Params);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }
        public static bool updateLuongNV(params SqlParameter[] Params)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_updateLuongNV";
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, Params);
            if (ds != null)
                return true;
            return false;
        }
        public static DataSet getNhanVienList2(params SqlParameter[] Params)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_TraCuuNhanVien2";
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, Params);
            if (ds != null)
                return ds;
            return null;
        }

        public static DataTable DangNhapNhanVien(string tendangnhap, string matkhau)
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_DangNhapNhanVien";
            SqlParameter[] sp = new SqlParameter[2];
            sp[0] = new SqlParameter("@tendangnhap", tendangnhap);
            sp[1] = new SqlParameter("@matkhau", matkhau);
            DataSet ds = SqlDataAccessHelper.LoadDataWithParameter(procName, sp);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }
    }
}
